<template>
	<view class="home-container">
		<swiper :autoplay="true" :indicator-dots="true" :interval="2000" :circular="true" style="height: 360rpx">
			<swiper-item>
				<!-- 广告位 -->
				<image @click="$tab.navigateTo('/pages/home/advert')" style="width: 100%;" mode="widthFix"
					src="@/static/images/index/banner-2.png" />
			</swiper-item>
			<swiper-item>
				<!-- 使用教程 -->
				<image @click="$tab.navigateTo('/pages/home/know')" style="width: 100%;" mode="widthFix"
					src="@/static/images/index/syjc.png" />
			</swiper-item>
			<swiper-item>
				<!-- 通知 -->
				<view id="zxgg">
					<view id="nb">
						<p v-for="(item,index ) of threeNewNotice" style="margin: 5px;line-height: 30px;">
							{{ index+ 1 +'. '+item.noticeTitle}} — {{item.createTime}}
						</p>
					</view>
				</view>
			</swiper-item>
		</swiper>

		<view class="grid">
			<view class="grid-item" @click="$tab.navigateTo('/pages/home/rights')">
				<view class="img"></view>
				<view class="desc">会员权益</view>
			</view>

			<view class="grid-item" @click="$modal.showToast('模块建设中~')">
				<view class="img"></view>
				<view class="desc">待办事项</view>
			</view>

			<view class="grid-item" @click="kefu()">
				<view class="img"></view>
				<view class="desc">客服中心</view>
			</view>
			<view class="grid-item" @click="$modal.showToast('模块建设中~')">
				<view class="img"></view>
				<view class="desc">关注公众号</view>
			</view>
		</view>

		<home-section title="个人查询" :showMore="morePer">
			<view class="section01">
				<view class="left" @click="openProduct(PER[0].id)">
					<view class="title">{{PER[0].name}}</view>
					<view class="text">{{PER[0].scene}}</view>
					<view class="btn">点击进入</view>
				</view>
				<view class="right">
					<view class="top" @click="openProduct(PER[1].id)">
						<view class="title">{{PER[1].name}}</view>
						<view class="btn">点击进入</view>
					</view>
					<view class="bottom" @click="openProduct(PER[2].id)">
						<view class="title">{{PER[2].name}}</view>
						<view class="btn">点击进入</view>
					</view>
				</view>
			</view>
		</home-section>

		<home-section title="企业查询" :showMore="moreCom" path="more?type=com">
			<view v-for="(item, index) of COM" @click="openProduct(item.id)" class="section02">
				<view class="title">
					{{item.name}}
				</view>
				<view class="desc">
					{{item.scene}}
				</view>
			</view>
		</home-section>
		<!-- 客服 -->
		<uni-popup ref="kf">
			<image mode="widthFix" src="@/static/images/gzh.jpg" />
		</uni-popup>
		<!-- 公众号 -->
		<uni-popup ref="popup" background-color="#FFF" borderRadius="10px 10px 10px 10px">
			<view style="text-align: center;width: 80vw;padding: 10px;">
				<image mode="aspectFit" :src="imgSrc" />
				<p style="text-align: center;background-color: aliceblue;padding: 5px;">
					微信内长按识别或保存二维码微信扫一扫即可关注公众号（请勿取消关注公众号，否则无法第一时间获取到佣金消息通知）</p>
			</view>
		</uni-popup>
		<!-- 通知 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" :showClose="false" confirmText="我知道了" title="系统通知"
				:content="firstUnRead.noticeTitle" @confirm="dialogConfirm" />
		</uni-popup>
	</view>
</template>

<script>
	import {
		homeProducts
	} from '@/api/product'

	import {
		QRCodeImg,
		indexNotice,
		readRecord
	} from '@/api/index'

	export default {
		data() {
			return {
				PER: [{
					name: "",
					scene: ""
				}, {
					name: "",
					scene: ""
				}, {
					name: "",
					scene: ""
				}],
				COM: [],
				morePer: false,
				moreCom: false,


				firstUnRead: {},
				threeNewNotice: [],
				QRURI: undefined,
				imgSrc: undefined
			}
		},
		onLoad() {
			homeProducts().then(res => {
				console.log('--res--', res)
				this.PER = res.PER;
				this.COM = res.COM;
				this.morePer = res.morePer
				this.moreCom = res.moreCom
			})

			indexNotice(this.$store.state.user.userid).then(res => {
				if (res.firstUnRead) {
					this.firstUnRead = res.firstUnRead
					this.$refs.alertDialog.open('center')
				}
				this.threeNewNotice = res.threeNewNotice
			})
		},

		methods: {
			kefu() {
				this.$refs.kf.open('center')
			},
			GZH() {
				QRCodeImg().then(res => {
					this.QRURI = res.url
					this.imgSrc = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + res.ticket
					this.$refs.popup.open('center')
				})
			},
			dialogConfirm() {
				readRecord(this.firstUnRead.noticeId)
			},
			openProduct(id) {
				this.$tab.navigateTo('/pages/home/popularize?id=' + id);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: linear-gradient(180deg, #c4d6ff, #f7f8fa);
		min-height: 100%;
	}

	.home-container {
		background-color: #F4F5FB;

		
		#zxgg {
			height: 360rpx;
			background-image: url("@/static/images/banner/tz.png");
			/* 背景图垂直、水平均居中 */
			background-position: center center;
			/* 背景图不平铺 */
			background-repeat: no-repeat;
			/* 当内容高度大于图片高度时，背景图像的位置相对于viewport固定 */
			background-attachment: fixed;
			/* 让背景图基于容器大小伸缩 */
			background-size: cover;
			padding-top: 48px;
		
			#nb {
				color: #fff;
				padding: 15px 10px;
				font-size: 15px;
			}
		}

		.grid {
			margin: 25rpx auto;
			width: 700rpx;
			height: 160rpx;
			border-radius: 12rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.grid-item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.img {
					width: 64rpx;
					height: 64rpx;
					background: url("@/static/images/index/grid-04.png") no-repeat center center;
					background-size: cover;
				}

				.desc {
					color: #333333;
					font-size: 24rpx;
					margin-top: 12rpx;
				}
			}

			.grid-item:nth-of-type(1) .img {
				background: url("@/static/images/index/grid-01.png") no-repeat center center;
				background-size: cover;
			}

			.grid-item:nth-of-type(2) .img {
				background: url("@/static/images/index/grid-03.png") no-repeat center center;
				background-size: cover;
			}

			.grid-item:nth-of-type(3) .img {
				background: url("@/static/images/index/grid-02.png") no-repeat center center;
				background-size: cover;
			}
		}

		.section01 {
			display: flex;
			justify-content: space-between;

			.title {
				color: #333333;
				font-size: 26rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
			}

			.btn {
				width: 120rpx;
				height: 40rpx;
				border-radius: 40rpx;
				background-color: rgba(38, 69, 194, 0.08);
				color: rgba(51, 51, 51, 0.40);
				font-size: 22rpx;
				font-family: PingFang SC, PingFang SC;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.left {
				padding: 16rpx 24rpx;
				box-sizing: border-box;
				width: 310rpx;
				height: 280rpx;
				background: url("@/static/images/index/section-left.png") no-repeat center center;
				background-size: contain;

				.text {
					color: rgba(51, 51, 51, 0.60);
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					margin-top: 16rpx;

					&:last-of-type {
						margin-top: 12rpx;
					}
				}

				.btn {
					margin-top: 12rpx;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.top {
					padding: 16rpx 24rpx;
					box-sizing: border-box;
					width: 312rpx;
					height: 132rpx;
					background: url("@/static/images/index/section-right-top.png") no-repeat center center;
					background-size: contain;

					.btn {
						margin-top: 16rpx;
					}
				}

				.bottom {
					padding: 16rpx 24rpx;
					box-sizing: border-box;
					background: url("@/static/images/index/section-right-bottom.png") no-repeat center center;
					background-size: contain;

					.btn {
						margin-top: 16rpx;
					}
				}
			}
		}

		.section02 {
			height: 120rpx;
			margin-top: 14rpx;
			border-radius: 8rpx;
			background: url("@/static/images/index/section02.png") no-repeat 438rpx 0,
				linear-gradient(to bottom, #F5F8FD 0, #E3EBFF 100%);
			background-size: contain;
			padding: 26rpx;
			box-sizing: border-box;

			.title {
				color: #334D9E;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
			}

			.desc {
				color: rgba(51, 77, 158, 0.60);
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				margin-top: 10rpx;
			}
		}
	}
</style>